<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品列表列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>商品名称：</label>
                                <input type="text" name="productName"/>
                            </li>
                            <li>
                                <label>产品规格：</label>
                                <input type="text" name="productSpecs"/>
                            </li>
                            <li>
                                <label>创建人：</label>
                                <input type="text" name="createdBy"/>
                            </li>
                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreatedDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreatedDate]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="core:product:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="core:product:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="core:product:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="core:product:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('core:product:edit')}]];
        var removeFlag = [[${@permission.hasPermi('core:product:remove')}]];
        var prefix = ctx + "core/product";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "产品列表",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'productId',
                    title: '商品ID',
                    visible: true
                },
                {
                    field: 'productName',
                    title: '商品名称'
                },
                {
                    field: 'productSpecs',
                    title: '产品规格'
                },
                {
                    field: 'productPrice',
                    title: '商品金额'
                },
                {
                    field: 'giftCardsList',
                    title: '礼品卡（已用/总数）',
                    formatter: function (value, row, index) {
                       let list=  row.giftCardsList;
                        if (list==null||list.length==0){
                            return "0/0"
                        } else {
                           let length  = list.length;
                           let size  = list.filter(item => item.isUsed == 1).length
                            return size+"/"+length;
                        }
                    }
                },
               /* {
                    field: 'createdBy',
                    title: '创建人'
                },
                {
                    field: 'createdDate',
                    title: '创建时间'
                },*/
                {
                    field: 'lastUpdatedName',
                    title: '最后更新人'
                },
                {
                    field: 'lastUpdatedDate',
                    title: '最后更新时间'
                },
               /* {
                    field: 'isDeleted',
                    title: '是否删除',
                    formatter: function (value, row, index) {
                        if (value==0){
                            return "未删除"
                        } else if (value==1) {
                            return "已删除"
                        }
                    }
                },*/
                {
                    field: 'imgUrl',
                    title: '图片',
                    formatter: function (value, row, index) {
                        return '<img src="' + value + '" style="height: 100px;width: 100px"/>'
                    }
                },
                // {
                //         field: 'descn',
                //         title: '商品详情',
                //
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="details('+ row.productId +')"><i class="fa fa-list-ul"></i>商品详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.productId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.productId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function details(id) {
            layer.open({
                type : 2,
                title : '详情',
                maxmin : true,
                shadeClose : false, // 点击遮罩关闭层
                area : [ '40%', '90%' ],
                content : prefix + '/details/' + id // iframe的url
            });
        }
    </script>
</body>
</html>